package com.smart.campus.controller;

import com.smart.campus.dto.AttendanceStatistics;
import com.smart.campus.dto.TeacherAttendance;
import com.smart.campus.pojo.PagedResponse;
import com.smart.campus.pojo.ResponseResult;
import com.smart.campus.service.TeacherAttendanceServiceFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @BelongsProject: smart-campus
 * @BelongsPackage: com.smart.campus.controller
 * @Author: JinBao shan
 * @date 2024/10/8 10:04
 * @Description: TODO
 * @Version: 1.0
 */

@Api(tags = "教师考勤管理")
@Slf4j
@RestController
@RequestMapping(value = "attendance")
public class TeacherAttendanceController {
    @Autowired
    private TeacherAttendanceServiceFeign attendanceServiceFeign;

    @ApiOperation(value = "教师考勤列表分页查询",httpMethod = "POST",notes = "教师考勤列表分页查询")
    @RequestMapping(value = "findTeacherAttendancePagination")
    public ResponseResult<PagedResponse<TeacherAttendance>> findTeacherAttendancePagination(@RequestBody TeacherAttendance attendance, @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        return new ResponseResult<>(200,"教师考勤列表信息分页查询成功",attendanceServiceFeign.findTeacherAttendancePagination(attendance,pageNum,pageSize));
    }

    @ApiOperation(value = "教师考勤信息新增",httpMethod = "POST",notes = "教师考勤信息新增")
    @RequestMapping(value = "addTeacherAttendance")
    public ResponseResult addTeacherAttendance(@RequestBody TeacherAttendance attendance){
        try {
            attendanceServiceFeign.addTeacherAttendance(attendance);
            return new ResponseResult<>(200,"教师考勤信息添加成功");
        } catch (Exception e) {
            return new ResponseResult<>(444,"教师考勤信息添加失败");
        }
    }

    @ApiOperation(value = "教师考勤信息回显",httpMethod = "POST",notes = "教师考勤信息回显")
    @RequestMapping(value = "getTeacherAttendanceById")
    public ResponseResult<TeacherAttendance> getTeacherAttendanceById(@RequestParam(value = "id") Integer id){
        return new ResponseResult<>(200,"教师考勤信息回显成功",attendanceServiceFeign.getTeacherAttendanceById(id));
    }

    @ApiOperation(value = "教师考勤信息修改",httpMethod = "POST",notes = "教师考勤信息修改")
    @RequestMapping(value = "updateTeacherAttendance")
    public ResponseResult updateTeacherAttendance(@RequestBody TeacherAttendance attendance){
        try {
            attendanceServiceFeign.updateTeacherAttendance(attendance);
            return new ResponseResult<>(200,"教师考勤信息修改成功");
        } catch (Exception e) {
            return new ResponseResult<>(444,"教师考勤信息修改失败");
        }
    }

    @ApiOperation(value = "教师考勤信息删除",httpMethod = "POST",notes = "教师考勤信息删除")
    @RequestMapping(value = "delTeacherAttendanceById")
    public ResponseResult delTeacherAttendanceById(@RequestParam(value = "id") Integer id){
        try {
            attendanceServiceFeign.delTeacherAttendanceById(id);
            return new ResponseResult<>(200,"教师考勤信息删除成功");
        } catch (Exception e) {
            return new ResponseResult<>(200,"教师考勤信息删除失败");
        }
    }


    @ApiOperation(value = "教师考勤统计",httpMethod = "POST",notes = "教师考勤统计")
    @RequestMapping(value = "queryAttendanceStatistics")
    public ResponseResult queryAttendanceStatistics(@RequestBody AttendanceStatistics attendanceStatistics){
        return new ResponseResult<>(200,"教师考勤统计分页查询成功",attendanceServiceFeign.queryAttendanceStatistics(attendanceStatistics));
    }
}
